/** 相关的接口 */
const express = require("express");
const router = express.Router();
const Response = require("../utils/Response.js");

// 引入mysql连接池
const pool = require("../utils/db.js");

//查询商品详情
router.post("/commodity/select", (req, resp) => {
  let sql = "select *  from commodity";
  pool.query(sql, (error, result) => {
    if (error) {
      resp.send(Response.error(500, error));
      throw error;
    }
    if (result.length === 0) {
      resp.send(Response.error(404, "没有该商品信息"));
    } else {
      resp.send(Response.ok(result));
    }
  });
});

// 将router对象导出
module.exports = router;
